package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.DateTimeEnum;
import com.xbongbong.paas.enums.PaySheetTypeEnum;
import com.xbongbong.paas.help.FormDataFormExplainHelper;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.pro.enums.AmountFlagEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.ForbiddenSettingEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.PaySheetEnum;
import com.xbongbong.saas.enums.dictionary.PayMethodEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import com.xbongbong.sys.enums.RoleEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/14 16:26
 * @since v1.0
 */
@Getter
public enum TempPaySheetEnum {
    //刷脚本专用枚举
    BASE_INFO(PaySheetEnum.BASE_INFO),
    PAY_SHEET_TYPE(PaySheetEnum.PAY_SHEET_TYPE),
    PAY_PLAN_NO(PaySheetEnum.PAY_PLAN_NO),
    LINK_SUPPLIER(PaySheetEnum.LINK_SUPPLIER),
    LINK_PURCHASE(PaySheetEnum.LINK_PURCHASE),
    PAY_PLAN(PaySheetEnum.PAY_PLAN),
    AMOUNT(PaySheetEnum.AMOUNT),
    WRITE_OFF_AMOUNT(PaySheetEnum.WRITE_OFF_AMOUNT),
    INVOICE_AMOUNT(PaySheetEnum.INVOICE_AMOUNT),
    BELONG_ID(PaySheetEnum.BELONG_ID),
    REAL_PAY_TIME(PaySheetEnum.REAL_PAY_TIME),
    FUND_ACCOUNT(PaySheetEnum.FUND_ACCOUNT),
    PAY_TYPE(PaySheetEnum.PAY_TYPE),
    SYSTEM_INFO(PaySheetEnum.SYSTEM_INFO),
    MEMO(PaySheetEnum.MEMO),
    FILE(PaySheetEnum.FILE),
    ORIGIN_ID(PaySheetEnum.ORIGIN_ID),
    CREATOR_ID(PaySheetEnum.CREATOR_ID),
    ADD_TIME(PaySheetEnum.ADD_TIME),
    UPDATE_TIME(PaySheetEnum.UPDATE_TIME),
    OWNER_ID(PaySheetEnum.OWNER_ID),
    COUSERID(PaySheetEnum.COUSERID),

    SUPPLIER_LINK_TEXT(PaySheetEnum.SUPPLIER_LINK_TEXT),
    PURCHASE_LINK_TEXT(PaySheetEnum.PURCHASE_LINK_TEXT),
    PAY_PLAN_LINK_TEXT(PaySheetEnum.PAY_PLAN_LINK_TEXT),
    ORIGIN_ID_LINK_TEXT(PaySheetEnum.ORIGIN_ID_LINK_TEXT),
    ;
    private PaySheetEnum anEnum;

    TempPaySheetEnum(PaySheetEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempPaySheetEnum> getAllEnum() {
        List<TempPaySheetEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static void initPayPlanNo(FieldAttrEntity fieldAttrEntity) {
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.PAY_SHEET.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.PAY_SHEET.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(PAY_PLAN_NO.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setNoRepeat(1);
        fieldAttrEntity.setSerialNumber(InitExplainsHelper.setSerialNumber(SerialNumberEnum.PAY_PLAN_SHEET_NO));
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setShowAttrPermission(BasicConstant.ZERO);
    }

    public static void initPaySheetType(FieldAttrEntity fieldAttrEntity){
        List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByEnum(PaySheetTypeEnum.class, fieldAttrEntity.getFieldType());
        for (ItemPoJo itemPoJo : itemPoJoList) {
            itemPoJo.setNoEdit(BasicConstant.ONE);
            itemPoJo.setNoMove(BasicConstant.ONE);
        }
        fieldAttrEntity.setItems(itemPoJoList);
        fieldAttrEntity.setDictionaryFlag(BasicConstant.TWO);
        fieldAttrEntity.setEditable(BasicConstant.ZERO);
        fieldAttrEntity.setIsForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setNoItemLink(BasicConstant.ONE);
        fieldAttrEntity.setItemBanDefault(BasicConstant.ONE);
        /*fieldAttrEntity.setEditForbidden(BasicConstant.ONE);*/
        fieldAttrEntity.setShowAttrPermission(BasicConstant.ZERO);
    }

    public static void initLinkPurchase(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.PURCHASE.getCode());
        fieldAttrEntity.setLinkedText(PURCHASE_LINK_TEXT.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(true);
        saasParticularAttributePoJo.setRelyAttr(LINK_SUPPLIER.anEnum.getAttr());
        saasParticularAttributePoJo.setRelyBusiness(XbbRefTypeEnum.SUPPLIER.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setBusinessType(XbbRefTypeEnum.PAY_SHEET.getCode());
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initOriginId(FieldAttrEntity fieldAttrEntity) {
        //改为付款单类型，因为打开关联原始付款单详情的时候，是要用付款单的type去得到tab、button等（通过data内的付款单类型来区分具体哪种类型的付款单）
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.PAY_SHEET.getCode());
        fieldAttrEntity.setLinkedText(ORIGIN_ID_LINK_TEXT.getAnEnum().getAttr());
        fieldAttrEntity.setBusinessType(XbbRefTypeEnum.PAY_SHEET.getCode());
    }

    public static void initAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setIsForbidden(0);
        //不允许修改默认值
        fieldAttrEntity.setItemBanDefault(BasicConstant.ONE);
        fieldAttrEntity.setForbiddenSettingList(Collections.singletonList(ForbiddenSettingEnum.DISABLE_DEFAULT.getAlias()));
    }

    public static void initWriteOffAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setIsForbidden(0);
        //不允许修改默认值
        fieldAttrEntity.setItemBanDefault(BasicConstant.ONE);
        fieldAttrEntity.setForbiddenSettingList(Collections.singletonList(ForbiddenSettingEnum.DISABLE_DEFAULT.getAlias()));
    }

    public static void initInvoiceAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setForbiddenSettingList(Collections.singletonList(ForbiddenSettingEnum.DISABLE_DEFAULT.getAlias()));
    }

    public static void initBelongId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initRealPayTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType( DateTimeEnum.TIME.getType());
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType("today");
        defaultAttrPoJo.setDefaultValue("");
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initFundAccount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDictionaryFlag(BasicConstant.TWO);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setNoItemLink(BasicConstant.ONE);
        fieldAttrEntity.setItemBanDefault(BasicConstant.ONE);
        fieldAttrEntity.setShowAttrPermission(BasicConstant.ZERO);
        fieldAttrEntity.setMemo("账户信息可在【管理中心-其他设置-资金账户】中自定义修改");
    }

    public static void initPayPlan(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.PAY_PLAN.getCode());
        fieldAttrEntity.setLinkedText(PAY_PLAN_LINK_TEXT.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(true);
        saasParticularAttributePoJo.setRelyAttr(LINK_PURCHASE.anEnum.getAttr());
        saasParticularAttributePoJo.setRelyBusiness(XbbRefTypeEnum.PURCHASE.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setEditable(BasicConstant.ZERO);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
    }

    /**
     * 初始化支付方式
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     * @author feng.zheng
     * @date 2019/1/17
     */
    public static void initPayType(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(PayMethodEnum.class, fieldAttrEntity.getFieldType()));
        fieldAttrEntity.setDictionaryFlag(1);
    }

    public static void initLinkSupplier(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.SUPPLIER.getCode());
        fieldAttrEntity.setLinkedText(SUPPLIER_LINK_TEXT.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    /**
     * 负责人
     * @param fieldAttrEntity
     */
    public static void initOwnerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setShowType(ShowTypeEnum.ALL.getCode());
        fieldAttrEntity.setEditHide(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setMultiple(1);
        fieldAttrEntity.setIsForbidden(BasicConstant.ZERO);
        //可新增权限：默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增负责人，支持自定义；
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        //可删除权限：默认【超级管理员、销售主管】可删除负责人，支持自定义；
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
    }

    /**
     * 协同人
     * @param fieldAttrEntity
     */
    public static void initCoUserId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setShowType(ShowTypeEnum.ALL.getCode());
        fieldAttrEntity.setEditHide(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setFormPermission(BasicConstant.ONE);
        fieldAttrEntity.setIsForbidden(BasicConstant.ZERO);
        //下面是一些高级属性
        //可新增权限，默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增负责人，支持自定义；
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        //可删除权限
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
    }
}
